package com.br.android.widingwheels.db;

import android.database.Cursor;
import android.database.sqlite.SQLiteCursor;
import android.database.sqlite.SQLiteCursorDriver;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQuery;
import android.database.sqlite.SQLiteDatabase.CursorFactory;

public class WidingWheelsCursor extends SQLiteCursor{

	public static final String QUERY = "SELECT * FROM gasto ORDER BY idgasto DESC";
	public static final String QUERY_SOMA_VALORES = "SELECT SUM(valorgasto) AS soma_valores from gasto";
	public static final String QUERY_SOMA_VALORES_POR_CATEGORIA = "SELECT categoriagasto, SUM(valorgasto) AS valor_por_categoria FROM gasto GROUP BY categoriagasto";
	
	public WidingWheelsCursor(SQLiteDatabase db, SQLiteCursorDriver driver,
			String editTable, SQLiteQuery query) {
		super(db, driver, editTable, query);
	}
	
	public static class Factory implements CursorFactory {

		@Override
		public Cursor newCursor(SQLiteDatabase db,
				SQLiteCursorDriver masterQuery, String editTable,
				SQLiteQuery query) {
			return new WidingWheelsCursor(db, masterQuery, editTable, query);
		}
	}

	public int getIdGasto(){
		return getInt(getColumnIndexOrThrow("idgasto"));
	}
	
	public String getNomeGasto(){
		return getString(getColumnIndexOrThrow("nomegasto"));
	}
	
	public String getDataGasto(){
		return getString(getColumnIndexOrThrow("datagasto"));
	}
	
	public double getValorGasto(){
		return getDouble(getColumnIndexOrThrow("valorgasto"));
	}
	
	public String getCategoriaGasto(){
		return getString(getColumnIndexOrThrow("categoriagasto"));
	}
	
	public double getLatitudeGasto(){
		return getDouble(getColumnIndexOrThrow("latitude"));
	}
	
	public double getLongitudeGasto(){
		return getDouble(getColumnIndexOrThrow("longitude"));
	}
	
	public String getNomeLocalGasto(){
		return getString(getColumnIndexOrThrow("nomelocal"));
	}
	
	public double getTotalSomaValores(){
		return getDouble(getColumnIndexOrThrow("soma_valores"));
	}
	
	public double getSomaPorCategoria(){
		return getDouble(getColumnIndexOrThrow("valor_por_categoria"));
	}
}
